import 'package:flutter/material.dart';

// 可扩展ThemeData实现更多自定义颜色
// https://github.com/jiang111/flutter_code/tree/master/provider_demo
enum ThemeType { Light, Dark }

class ThemeModel with ChangeNotifier {
  // 默认主题
  // List<ThemeData> themeList;
  ThemeData _defaultTheme = ThemeData(
      brightness: Brightness.light,
      primaryColor: Colors.white,
      splashColor: Colors.transparent,
      tooltipTheme: TooltipThemeData(verticalOffset: -100000));

  ThemeData themeData;

  ThemeType currentType;

  ThemeModel(ThemeType type) {
    _update(type, notify: false);
  }

  void reverse() {
    currentType == ThemeType.Light
        ? this._update(ThemeType.Dark)
        : this._update(ThemeType.Light);
  }

  void _update(ThemeType type, {bool notify = true}) {
    currentType = type;
    this.themeData =
        (type == ThemeType.Dark) ? ThemeData.dark() : _defaultTheme;
    // 通知主题变更
    notify ?? notifyListeners();
  }
}
